function y = yldmat(sd,md,id,rv,price,cpn,basis)
%YLDMAT Yield with interest at maturity.
%   YLDMAT(SD,MD,ID,RV,PRICE,CPN,BASIS) returns the yield of a security
%   paying interest at maturity.  SD is the settlement date, MD is the
%   maturity date, ID is the issue date, RV is the redemption value,
%   PRICE is the price, CPN is the coupon rate, and BASIS is the day
%   count basis: 0 = actual/actual (default), 1 = 30/360, 2 = actual/360,
%   3 = actual/365.  Enter dates as serial date numbers or date strings.
%
%   Y = YLDMAT(SD,MD,ID,RV,PRICE,CPN)
%   Y = YLDMAT(SD,MD,ID,RV,PRICE,CPN,BASIS)
%
%   Enter dates as serial date numbers or date strings.
%
%   Inputs:
%       SD      -  Settlement date
%       MD      -  Maturity date
%       ID      -  Issue date
%       RV      -  Redemption value
%       PRICE   -  Price
%       CPN     -  Coupon rate
%
%   Optional Inputs:
%       Basis   -  the day-count basis:
%                  0 = actual/actual (default)
%                  1 = 30/360 SIA
%                  2 = actual/360
%                  3 = actual/365
%                  4 = 30/360 PSA
%                  5 = 30/360 ISDA
%                  6 = 30E/360
%                  7 = actual/365 Japanese
%                  8 - actual/actual ISMA
%                  9 - actual/360 ISMA
%                 10 - actual/365 ISMA
%                 11 - 30/360 ISMA
%                 12 - actual/365 ISDA
%                 13 - bus/252
%
%   Using the following data,
%
%       SD = '02/07/1992'
%       MD = '04/13/1992'
%       ID = '10/11/1991'
%       RV = 100
%       PRICE = 99.98
%       CPN = 0.0608
%       BASIS = 1
%
%   y = yldmat(sd,md,id,rv,price,cpn,basis)
%
%   returns y = 0.0607 or 6.07%.
%
%   See also PRBOND, YLDBOND, YLDDISC, PRMAT.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formula 3.

% Copyright 1995-2006 The MathWorks, Inc.
% $Revision: 1.6.2.8 $   $Date: 2009/05/07 18:23:37 $

if nargin < 7
    basis = zeros(size(rv));
end

if nargin < 6
    error('finance:yldmat:notEnoughInputs',...
        'Missing one of SD, MD, ID, RV, CPN, and PRICE.');
end

[cpn, sd, md, ~, basis, ~, id, ...
    FirstCouponDate, LastCouponDate, StartDate, Face] = ...
    instargbond(cpn,sd,md,[],basis,[],id,[],[],[],rv); %#ok<NASGU>

[sd,md,id,rv,price,cpn,basis] = ...
    finargsz(1,sd,md,id,rv,price,cpn,basis);

num2 = (1+(yearfrac(id,md,basis).*cpn))- ...
    (price./rv+(yearfrac(id,sd,basis).*cpn));
den2 = price./rv+(yearfrac(id,sd,basis).*cpn);

y = reshape((num2./den2).*(1/yearfrac(sd,md,basis)),size(rv));